using System;
using System.Collections.Generic;

using log4net;

using GymManager.Exception;
using GymManager.Persistence.DAO;
using GymManager.Persistence.VO;

namespace GymManager.Business
{
    /// <summary>
    /// Class responsible by providing services regarding role
    /// </summary>
    public class RoleServices
    {
        // logger instance
        private ILog _logManager = LogManager.GetLogger(typeof(RoleServices));

        /// <summary>
        /// Method responsible by getting information about all avaliable roles
        /// </summary>
        /// <returns>List of all avaliable roles</returns>
        /// <see cref="GymManager.Exception.BusinessException"/>
        public IList<Role> findAll()
        {
            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("Begin Method");
            }
            
            IList<Role> roleList = null;

            try
            {
                // getting information about roles
                RoleDAO roleDAO = new RoleDAO();
                roleList = roleDAO.findAll();                
            }
            catch (PersistenceException)
            {
                throw new BusinessException();
            }            
            
            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("End Method");
            }

            return roleList;
        }
    }
}
